<?php
//No direct access
defined('_JEXEC') or die('Restricted access');
?>
<div id="ownservices">
 <div id="mainmenuownservice"><?php echo MenuHelper::nav(); ?></div>
	<div id="mainownservice">
	<h3><?php echo JText::_('OWNSERVICE_TRANSFERRING_TRANSACTIONS'); ?></h3>
	<hr />
	<div id="toolbar">
		<a class="toolbar" onclick="javascript:if(document.adminForm.boxchecked.value==0){alert('<?php echo JText::_('OWNSERVICE_SELECT_ITEM_TRANSFER_DOWNLOAD'); ?>');}else{submitbutton('download');}" href="#">
			<span title="<?php echo JText::_('OWNSERVICE_DOWNLOAD'); ?>" class="icon-32-export"></span>
			<?php echo JText::_('OWNSERVICE_DOWNLOAD'); ?>
		</a>
		<a class="toolbar" onclick="javascript:if(document.adminForm.boxchecked.value==0){alert('<?php echo JText::_('OWNSERVICE_SELECT_ITEM_TRANSFER_SUCCESS'); ?>');}else{ submitbutton('success')}" href="#">
			<span title="<?php echo JText::_('OWNSERVICE_SUCCESS'); ?>" class="icon-32-publish"></span>
			<?php echo JText::_('OWNSERVICE_SUCCESS'); ?>
		</a>
		<a class="toolbar" onclick="javascript:if(document.adminForm.boxchecked.value==0){alert('<?php echo JText::_('OWNSERVICE_SELECT_ITEM_TRANSFER_FAIL'); ?>');}else{ submitbutton('fail')}" href="#">
			<span title="<?php echo JText::_('OWNSERVICE_FAIL'); ?>" class="icon-32-unpublish"></span>
			<?php echo JText::_('OWNSERVICE_FAIL'); ?>
		</a>
	</div>
	<div class="clear"> </div>
	<form action="<?php echo JRoute::_('index.php?option=com_ownservice'); ?>" method="post" name="adminForm">
		<table class="adminlist" cellspacing="1">
			<tr>
				<td align="center" class="tablelist">
					<?php echo JText::_('NUM'); ?>
				</td>
				<td align="center" class="tablelist">
					<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo $this->total; ?>);" />
				</td>
				<td align="center" class="tablelist">
					<?php echo JHTML::_('grid.sort',  'OWNSERVICE_BANK_NAME', 'a.bank_name', $this->lists['order_Dir'], $this->lists['order'] ); ?>
				</td>
				<td align="center" class="tablelist">
					<?php echo JHTML::_('grid.sort',  'OWNSERVICE_ACCOUNT_NO', 't.account', $this->lists['order_Dir'], $this->lists['order'] ); ?>
				</td>
				<td align="center" width="5%" class="tablelist">
					<?php echo JHTML::_('grid.sort',  'OWNSERVICE_ACCOUNT_NAME', 'a.account_name', $this->lists['order_Dir'], $this->lists['order'] ); ?>
				</td>
				<td align="center" class="tablelist">
					<?php echo JHTML::_('grid.sort',  'OWNSERVICE_TOTAL_EXCHANGE', 't.total', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					<br />(THB)
				</td>
				<td align="center" class="tablelist">
					<?php echo JHTML::_('grid.sort',  'OWNSERVICE_AMOUNT_TRANSFER', 't.amount', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					<br />(AUD)
				</td>
				<td align="center" class="tablelist">
					<?php echo JHTML::_('grid.sort',  'OWNSERVICE_BRANCH_CITY', 'a.branch_city', $this->lists['order_Dir'], $this->lists['order'] ); ?>
				</td>
				<td align="center" class="tablelist">
					<?php echo JHTML::_('grid.sort',  'OWNSERVICE_PHONE', 'a.phone_no', $this->lists['order_Dir'], $this->lists['order'] ); ?>
				</td>
				<td align="center" class="tablelist">
					<?php echo JHTML::_('grid.sort',  'OWNSERVICE_SENDER', 'u.username', $this->lists['order_Dir'], $this->lists['order'] ); ?>
				</td>
				<td align="center" class="tablelist">
					<?php echo JHTML::_('grid.sort',  'OWNSERVICE_DISTRIBUTED_DATE', 't.requested_date', $this->lists['order_Dir'], $this->lists['order'] ); ?>
				</td>
				<td align="center" class="tablelist">
					<?php echo JText::_('OWNSERVICE_COMMENT'); ?>
				</td>
			</tr>
			<tbody>
			<?php
				$j = 0;
				$priceformat = OwnserviceHelper::getParams('price_format', '#,###.##');
				$dateformat  = OwnserviceHelper::getParams('date_format', '%d/%m/%Y');
				//check data transfer
				if(count($this->rows) > 0):
				    //Date
					foreach($this->rows as $rows):
					?>
					<tr>
						<td colspan="12"><strong><?php echo JText::_('OWNSERVICE_DISTRIBUTED_DATE').': '.$rows->requested_date; ?></strong></td>
					</tr>
					<?php
					   if(count($rows->session) > 0):
						  //Sessions
						  foreach($rows->session as $sessions):
						  ?>
						  <tr>
							 <td colspan="12">
								<span style="background-color: yellow; border: 1px solid; padding: 5px 5px; clear: both; font-weight: bold;">
									Session: <?php echo $sessions->session; ?>
								</span>	
							 </td>
						  </tr>
						  <?php
							//transaction
							if(count($sessions->transactions) > 0):
								$k = 0;
								$i = 0;
								//for($i=0,$n=count($sessions->transactions);$i<$n;$i++):
								foreach($sessions->transactions as $row):
									//$row = $sessions->transactions[$i];
									$checked = JHTML::_('grid.checkedout', $row, $j );
						?>
						<tr class="<?php echo "row$k"; ?>">
							<td align="center" class="inner_tablelist">
								<?php echo ($i+1); ?>
							</td>
							<td align="center" class="inner_tablelist">
								<?php echo $checked; ?>
							</td>
							<td align="center" class="inner_tablelist">
								<?php if($row->bank_name=='other'): ?>
									<?php echo $row->bank_other; ?>
								<?php else: ?>
									<?php echo $row->bank_name; ?>
								<?php endif; ?>
							</td>
							<td align="center" class="inner_tablelist">
								<?php echo OwnserviceHelper::accountFormat($row->account); ?>
							</td>
							<td align="center" class="inner_tablelist">
								<?php echo $row->account_name; ?>
							</td>
							<td class="inner_tablelist" align="right" nowrap="nowrap">
								<?php if(!$row->iscore): ?>
									<div style="border-bottom: 1px solid;">
										<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->total_th); ?> THB
									</div>
								<?php endif; ?>
								<div>
									<span class="<?php echo ($row->extratotal > 0.00?'red':''); ?>">
										<?php
											if($row->extratotal > 0.00) {
												echo OwnserviceHelper::moneyFormat($priceformat, $row->extratotal);
											} else {
												echo OwnserviceHelper::moneyFormat($priceformat, ( ($row->amount * ($row->rate+$row->extrarate)) - ($row->bankfee+$row->extrabfee))); 
											}
										?>
									</span> <?php /*echo $row->rate_code;*/ ?>
								</div>
							</td>
							<td class="inner_tablelist" align="center">
								<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->amount); ?>
							</td>
							<td align="center" class="inner_tablelist">
								<?php echo $row->branch_city; ?>
							</td>
							<td align="center" class="inner_tablelist">
								<?php echo $row->phone_no; ?>
							</td>
							<td class="inner_tablelist">
								<?php echo $row->username; ?>
							</td>
							<td align="center" class="inner_tablelist">
								<?php echo JHTML::_('date', $row->requested_date, $dateformat); ?>
							</td>
							<td class="inner_tablelist" align="center">
								<input type="text" name="comment[<?php echo $row->id; ?>]" id="comment<?php echo $i; ?>" value="<?php echo $row->comment; ?>" maxlength="255" size="20" class="inputbox" />
							</td>
						</tr>
								<?php $k = 1 - $k; $i++; $j++; endforeach; ?>
							<?php endif; ?>
						<?php endforeach; ?>
					<?php endif; ?>
				<?php endforeach; ?>
			<?php endif; ?>
			</tbody>
		</table>
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="id" value="" />
		<input type="hidden" name="status" value="" />
		<input type="hidden" name="option" value="com_ownservice" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="Itemid" value="<?php echo JRequest::getVar('Itemid'); ?>" />
		<input type="hidden" name="controller" value="transaction" />
		<input type="hidden" name="view" value="transactions" />
		<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
		<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
		<?php echo JHTML::_( 'form.token' ); ?>
		</form>
	</div>
</div>